home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group95b.txt / 000010_cargo@ironwood.cray.com _Thu Feb 9 10:46:19 1995.msg < prev    next >
Internet Message Format  |  1995-09-18  |  3KB

  1. Received: from optima.CS.Arizona.EDU by cheltenham.CS.Arizona.EDU; Thu, 9 Feb 1995 09:46:27 MST
  2. Received: from timbuk.cray.com by optima.cs.arizona.edu (5.65c/15) via SMTP
  3.     id AA01704; Thu, 9 Feb 1995 09:46:23 MST
  4. Received: from sdiv.cray.com (ironwood.cray.com [128.162.21.36]) by timbuk.cray.com (8.6.9/CRI-fence-1.4) with SMTP id KAA03025 for <icon-group@cs.arizona.edu>; Thu, 9 Feb 1995 10:46:21 -0600
  5. Received: from fir121 by sdiv.cray.com (5.0/CRI-5.15.b.orgabbr Sdiv)
  6.     id AA12841; Thu, 9 Feb 1995 10:46:20 -0600
  7. From: cargo@ironwood.cray.com (David Cargo)
  8. Received: by fir121 (5.0/btd-b3)
  9.           id AA02575; Thu, 9 Feb 1995 10:46:19 -0600
  10. Message-Id: <9502091646.AA02575@fir121>
  11. Date: Thu, 9 Feb 1995 10:46:19 -0600
  12. To: icon-group@cs.arizona.edu
  13. Subject: string invocation example
  14. X-Mailer: [XMailTool v3.1.0]
  15. Content-Length: 1658
  16.  
  17.  
  18. The February Icon Analyst has a cover article about string invocation.
  19. I wrote this program to take advantage of string invocation for
  20. filtering text files in a flexible fashion.
  21.  
  22. ############################################################################
  23. #
  24. #    File:     filter.icn
  25. #
  26. #    Subject:  Program to apply Icon functions to lines of input
  27. #
  28. #    Author:   David S. Cargo
  29. #
  30. #    Date:     February 9, 1995
  31. #
  32. ############################################################################
  33. #
  34. #    Version:  1.1
  35. #
  36. ############################################################################
  37. #
  38. #   This program uses string invocation to apply an Icon function to lines
  39. #   of input to produce lines of output.  
  40. #  
  41. #
  42. ############################################################################
  43. #
  44. #  Links: none
  45. #
  46. #  Requires: string invocation
  47. #
  48. ############################################################################
  49.  
  50. procedure main(args)
  51.     local arglist, function_name, line
  52.     (*args > 0) | Usage()
  53.     function_name := get(args)
  54.     (function_name == function()) | possible_match(function_name)
  55.     if *args = 0
  56.     then while line := read() do write(function_name(line))
  57.     else
  58.         {
  59.     arglist := [] ||| args
  60.     while arglist[1] := read() do write(function_name!arglist)
  61.     }
  62.     return
  63. end
  64.  
  65. procedure Usage()
  66.     every write(function())
  67.     stop("Usage: filter functionname [arg1 [arg2 ...]] <stdin >stdout")
  68. end
  69.  
  70. procedure possible_match(function_name)
  71.     local fname
  72.     write(image(function_name), " is not the name of any function.")
  73.     every fname := function() do
  74.         if find(function_name, fname)
  75.         then write(fname)
  76.     stop()
  77. end